package com.suxin.websocket.model;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

/**
 * @author Tang
 * @classname BaseModel
 * @description [  ]
 * @date 2022/3/24 13:25
 */
@Data
public class BaseModel {

    /**
     * 消息类型
     */
    private Integer type;

    /**
     * 要推送给用户的id
     */
    private String key;

    public BaseModel(Integer type) {
        this.type = type;
    }

    public static BaseModel getType(String message) {
        JSONObject jsonObject = JSONObject.parseObject(message);
        int type = Integer.parseInt(jsonObject.get("type").toString());
        switch (type) {
            case 0:
                return JSONObject.parseObject(message, HeartbeatModel.class);
            case 1:
                return JSONObject.parseObject(message, RelationRequestModel.class);
            case 2:
                return JSONObject.parseObject(message, RewardClearModel.class);
            default:
                return null;
        }
    }
}